var express = require("express");

var items = [
    { name : "hugohoo0", age : 20 },
    { name : "hugohoo1", age : 21 },
    { name : "hugohoo2", age : 22 },
    { name : "hugohoo3", age : 23 },
    { name : "hugohoo4", age : 24 },
    { name : "hugohoo5", age : 25 },
    { name : "hugohoo6", age : 26 },
    { name : "hugohoo7", age : 27 },
    { name : "hugohoo8", age : 28 },
];

var app = express();
app.all("*", function(req, res, next){
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "*");
    res.header("Access-Control-Allow-Methods", "*");
    next();
});

app.get("/test", onRequest);

app.listen(3000);

console.log("Server is listening at http://localhost:3000");

function onRequest(req, res){
    res.header("Access-Control-Allow-Origin", "*");
    res.send({message : items});
}